package com.powergisol.gis.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.powergisol.gis.dto.*;
import com.powergisol.gis.entity.TabArea;
import com.powergisol.gis.service.BoreholeQueryService;
import com.powergisol.gis.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;


@RestController
@RequestMapping("/query")
public class BoreholeQueryController {
    @Autowired
    BoreholeQueryService boreholeQueryService;

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping(value = "getArea", method = RequestMethod.POST)
    @ApiOperation(value = "获取区域下拉框", notes = "获取区域下拉框")
    public Result getArea(@RequestBody QueryDataDTO dto){
        Result r = new Result();
        List<TabArea> list = boreholeQueryService.getArea(dto);
        r.setData(list);
        return r;
    }

    @RequestMapping(value = "boreHoleList", method = RequestMethod.POST)
    @ApiOperation(value = "钻孔数据列表查询", notes = "钻孔数据列表查询")
    public Result boreHoleList(@RequestBody QueryDataDTO dto){
        return boreholeQueryService.boreHoleList(dto);
    }

    @RequestMapping(value = "boreHoleNum", method = RequestMethod.POST)
    @ApiOperation(value = "钻孔数", notes = "钻孔数")
    public Result boreHoleNum(@RequestBody QueryDataDTO dto){
        Result r = new Result();
        Integer num = boreholeQueryService.broeHoleNum(dto);
        r.setCount(num);
        return r;
    }

    @RequestMapping(value = "boreHole2DNum", method = RequestMethod.POST)
    @ApiOperation(value = "钻孔数", notes = "钻孔数")
    public Result boreHole2DNum(@RequestBody QueryDataDTO dto){
        Result r = new Result();
        Integer num = boreholeQueryService.broeHole2DNum(dto);
        r.setCount(num);
        return r;
    }


    @RequestMapping(value = "boreHolePoint", method = RequestMethod.POST)
    @ApiOperation(value = "钻孔点数据查询", notes = "钻孔点数据查询")
    public Result boreHolePoint(@RequestBody QueryDataDTO dto){
        Result r = new Result();
        try {
            Future<List<ZkPointDataDTO>> data = boreholeQueryService.boreHolePointF(dto);
            r.setData(data.get());
            return r;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return r;
    }

    @RequestMapping(value = "boreHole", method = RequestMethod.POST)
    @ApiOperation(value = "钻孔3D数据查询", notes = "钻孔3D数据查询")
    public Result boreHole(@RequestBody QueryDataDTO dto){
        Result r = new Result();
        try {
            Future<List<ZkDataDTO>> list = boreholeQueryService.boreHoleF(dto);
            r.setData(list.get());
            return r;
        } catch (InterruptedException e) {
            e.printStackTrace();
            r.failure(-1,"系统异常");
        } catch (ExecutionException e) {
            e.printStackTrace();
            r.failure(-1,"系统异常");
        } catch (Exception e){
            r.failure(-1,e.getMessage());
        }
        return r;
    }


    @RequestMapping(value = "boreHoleProject", method = RequestMethod.POST)
    @ApiOperation(value = "查询条件下对应的项目", notes = "查询条件下对应的项目")
    public Result boreHoleProject(@RequestBody QueryDataDTO dto){
       Result r = new Result();
        List<TabProjectDTO> list = boreholeQueryService.boreHoleProject(dto);
        return r.success(list);
    }


//    @RequestMapping(value = "boreHole3D", method = RequestMethod.POST)
//    @ApiOperation(value = "钻孔数据3d查询", notes = "钻孔数据3d查询")
//    public Result boreHole3D(QueryDataDTO dto){
//        Result r = new Result();
//        Map<String,Object> map = boreholeQueryService.boreHole3D(dto);
//        return r.success(map);
//    }


    @RequestMapping(value = "boreHoleDetail", method = RequestMethod.POST)
    @ApiOperation(value = "钻孔详情（项目、土层、水位）", notes = "钻孔详情（项目、土层、水位）")
    public Result boreHoleDetail(QueryDataDTO dto){
        Result r = new Result();
        return r;
    }

    @RequestMapping(value = "boreHoleTc", method = RequestMethod.POST)
    @ApiOperation(value = "钻孔详情（土层）", notes = "钻孔详情（土层）")
    public Result boreHoleTc(QueryDataDTO dto){
        Result r = new Result();
        return r;
    }



    @RequestMapping(value = "upZkCode", method = RequestMethod.GET)
    @ApiOperation(value = "钻孔数据查询", notes = "钻孔数据查询")
    public Result upZkCode(){
        Result r = new Result();
        boreholeQueryService.upZkCode();
        return r;
    }

}
